package com.example.simpledemo;

import com.example.grpc.HelloRequest;
import com.example.grpc.HelloResponse;
import com.example.grpc.HelloServiceGrpc;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;

public class HelloClient {
    public static void main(String[] args) {
        // 创建gRPC通道
        ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8080)
                .usePlaintext()
                .build();

        // 创建gRPC客户端存根
        HelloServiceGrpc.HelloServiceBlockingStub stub = HelloServiceGrpc.newBlockingStub(channel);

        // 构建请求
        HelloRequest request = HelloRequest.newBuilder().setName("World").build();

        // 调用远程方法
        HelloResponse response = stub.sayHello(request);

        // 处理响应结果
        System.out.println(response.getMessage());

        // 关闭通道
        channel.shutdown();
    }
}